package com.ruoyi.duty.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.duty.domain.bo.DutyJdywpxBo;
import com.ruoyi.duty.domain.vo.DutyJdywpxVo;
import com.ruoyi.duty.service.IDutyJdywpxService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 禁毒业务培训
 *
 * @author xiaohao
 * @date 2023-01-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/duty/jdywpx")
public class DutyJdywpxController extends BaseController {

    private final IDutyJdywpxService iDutyJdywpxService;

    /**
     * 查询禁毒业务培训列表
     */
    @GetMapping("/list")
    public TableDataInfo<DutyJdywpxVo> list(DutyJdywpxBo bo, PageQuery pageQuery) {
        return iDutyJdywpxService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出禁毒业务培训列表
     */
    @Log(title = "禁毒业务培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DutyJdywpxBo bo, HttpServletResponse response) {
        List<DutyJdywpxVo> list = iDutyJdywpxService.queryList(bo);
        ExcelUtil.exportExcel(list, "禁毒业务培训", DutyJdywpxVo.class, response);
    }

    /**
     * 获取禁毒业务培训详细信息
     *
     * @param jdywpxId 主键
     */
    @GetMapping("/{jdywpxId}")
    public R<DutyJdywpxVo> getInfo(@NotNull(message = "主键不能为空")
                                   @PathVariable Long jdywpxId) {
        return R.ok(iDutyJdywpxService.queryById(jdywpxId));
    }

    /**
     * 新增禁毒业务培训
     */
    @SaCheckPermission("duty:jdywpx:add")
    @Log(title = "禁毒业务培训", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DutyJdywpxBo bo) {
        return toAjax(iDutyJdywpxService.insertByBo(bo));
    }

    /**
     * 修改禁毒业务培训
     */
    @SaCheckPermission("duty:jdywpx:edit")
    @Log(title = "禁毒业务培训", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DutyJdywpxBo bo) {
        return toAjax(iDutyJdywpxService.updateByBo(bo));
    }

    /**
     * 删除禁毒业务培训
     *
     * @param jdywpxIds 主键串
     */
    @SaCheckPermission("duty:jdywpx:remove")
    @Log(title = "禁毒业务培训", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jdywpxIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] jdywpxIds) {
        return toAjax(iDutyJdywpxService.deleteWithValidByIds(Arrays.asList(jdywpxIds), true));
    }
}
